package com.chenxi.vhr.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息中转 交换机配置
 * @author : zhangchenxi
 * @create : 2022-02-13
 **/
@Configuration
public class MessageExchangeConfig {

    // 消息队列
    @Bean
    Queue mailQueue() {
        return new Queue("Mail-Queue");
    }

    /**
     * Direct交换机
     * DirectExchange构造函数参数
     * 参数1: 交换机名称
     * 参数2: 重启后是否依然有效
     * 参数3: 长期未用时是否删除
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange("Direct_Exchange", true, false);
    }

    // 绑定队列和交换机
    @Bean
    Binding bindingBuilder() {
        return BindingBuilder.bind(mailQueue()).to(directExchange()).with("Direct");
    }
}
